package com.mtnz.njk.Controller;

import com.mtnz.njk.Service.*;
import com.mtnz.njk.model.ResearchModel;
import com.mtnz.njk.result.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 帖子的控制类
 * @Author: ZPX
 * @CreateDate: 2019/7/12 16:19
 * @Version: 1.0
 */
@RestController
@RequestMapping("/community")
public class CommunityController {

    @Autowired
    ResearchService researchService;

    @Autowired
    CommentResearchService commentResearchService;

    @Autowired
    CommunityService communityService;

    @Autowired
    AskService askService;

    @Autowired
    CommentAskService commentAskService;

    /**
     * 研究院发帖
     *
     * @return
     * @throws Exception
     */
    @PostMapping("saveResearch")
    public ResponseResult saveResearch(@RequestBody  ResearchModel researchModel) throws Exception {
        return researchService.saveResearch(researchModel);
    }

    /**
     * 帖子详情
     *
     * @param researchId
     * @return
     * @throws Exception
     */
        @PostMapping("/showListResearch")
    public ResponseResult showListResearch(Integer researchId ,String userId) throws Exception {
        return researchService.showListResearch(researchId,userId);
    }

    /**
     * @Description: 显示置顶帖子
     * @author: ZPX
     * @param: 商品ID
     * @return:
     * @exception:
     * @date: 2019/7/15 9:50
     */
    @PostMapping("/topResearch")
    public ResponseResult topResearch(String productId) throws Exception {
        return researchService.topResearch(productId);
    }

    /**
     * 商品对应的帖子
     * @param productId
     * @return
     * @throws Exception
     */
    @PostMapping("/showResearch")
    public ResponseResult showResearch(String productId,String dateStatus, @RequestParam(defaultValue = "1")Integer pageNum,@RequestParam(defaultValue = "10")Integer pageSize) throws Exception {
        return researchService.showResearch(productId,dateStatus,pageNum,pageSize);
    }

    /**
     * 研究院评论
     * @param researchId
     * @param userId
     * @param message
     * @return
     * @throws Exception
     */
    @PostMapping("/saveCommentResearch")
    public ResponseResult saveCommentResearch(String researchId, String userId, String message, String img) throws Exception {
        return commentResearchService.saveCommentResearch(researchId, userId, message, img);
    }

    /**
     * 回复评论
     * @param userId
     * @param researchId
     * @param message
     * @param commentResearchId
     * @return
     */
    @PostMapping("/commentResearchReply")
    public ResponseResult commentResearchReply(String userId, String researchId, String message, String commentResearchId) throws Exception {
        return commentResearchService.commentResearchReply(userId,researchId,message,commentResearchId);
    }

    /**
     * 回复评论回复
     * @param userId
     * @param researchId
     * @param message
     * @param pid
     * @return
     */
    @PostMapping("commentResearchReplys")
    public ResponseResult commentResearchReplyS(String userId, String researchId, String message,String replyId,String pid) throws Exception{
        return  commentResearchService.commentResearchReplys(userId,researchId,message,replyId,pid);
    }

    /**
     * 商品研究社帖子详情下评论列表
     *
     * @param researchId
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/findComment",produces="application/json; utf-8")
    public ResponseResult findComment(Integer researchId,String userId,@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) throws Exception {

        return commentResearchService.findComment(researchId,userId,pageNum,pageSize);
    }

    /**
     * 研究院点赞
     *
     * @param researchId
     * @param userId
     * @return
     * @throws Exception
     */
    @PostMapping("/praiseResearch")
    public ResponseResult praiseResearch(Integer researchId, String userId) throws Exception {
        return researchService.praiseResearch(researchId, userId);
    }

    /**
     * 研究院评论点赞
     *
     * @param commentResearchId
     * @param userId
     * @return
     * @throws Exception
     */
    @PostMapping("/praiseCommentResearch")
    public ResponseResult praiseCommentResearch(Integer commentResearchId, String userId) throws Exception {
        return commentResearchService.praiseCommentResearch(commentResearchId, userId);
    }

    /**
     * 是否置顶
     * @param researchId
     * @return
     */
    @PostMapping("/updateTopStatus")
    public ResponseResult updateTopStatus(Integer researchId) {
        return researchService.updateTopStatus(researchId);
    }

    /**
     * 社区首页
     * @param userId
     * @param pageNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @PostMapping("/findCommunity")
    public ResponseResult findCommunity(String userId,String status, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize)throws Exception{
      return   communityService.findCommunity(userId,status,pageNum,pageSize);
    }

    @PostMapping("/findUserCommunity")
    public ResponseResult findUserCommunity(String userId, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize)throws Exception{
        return   communityService.findUserCommunity(userId,pageNum,pageSize);
    }

    /**
     * 首页广告图首页广告图和社区置顶内容
     * @return
     * @throws Exception
     */
    @PostMapping("/homeBanner")
    public ResponseResult homeBanner() throws Exception {
    return communityService.homeBanner();
    }

    /**
     * 提问详情
     */
    @PostMapping("/showAsk")
    public ResponseResult showAsk(String askId,String userId)throws Exception{
        return  askService.showAsk(askId,userId);
    }

    /**
     * 点赞提问
     */
    @PostMapping("/praiseAsk")
    public ResponseResult praiseAsk(String askId,String userId)throws Exception{
    return askService.praiseAsk(askId,userId);
    }

    /**
     * 发布提问评论
     */
    @PostMapping("/commentAsk")
    public ResponseResult CommentAsk(String userId,String askId,String message,String img)throws Exception {
        return commentAskService.CommentAsk(userId,askId,message,img);
    }

    /**
     * 提问评论列表
     */
    @PostMapping("/findCommentList")
    public ResponseResult findCommentList(String askId,String userId,@RequestParam(defaultValue = "1")Integer pageNum,@RequestParam(defaultValue = "10") Integer pageSize)throws Exception{
        return commentAskService.findCommentList(askId,userId,pageNum,pageSize);
    }

    /**
     *关注提问和取消关注
     */
    @PostMapping("/collectionAsk")
    public ResponseResult collectionAsk(String status,String askId,String userId)throws Exception{
        return askService.collectionAsk(status,askId,userId);
    }

    /**
     * 发布提问
     */
    @PostMapping("/saveAsk")
    public ResponseResult saveAsk(String message, String userId, String img, String lat, String lng) throws Exception {
        return askService.saveAsk(message,userId,img,lat,lng);
    }

    /**
     * 回复提问评论
     */
    @PostMapping("/replyCommentAsk")
    public ResponseResult replyCommentAsk(String userId, String askId, String message, String commentAskId)throws Exception{
        return commentAskService.replyCommentAsk(userId,askId,message,commentAskId);
    }

    /**
     * 回复提问评论回复
     */
    @PostMapping("/replyCommentAsks")
    public ResponseResult replyCommentAsks(String userId, String askId, String message, String replyId,String pid)throws Exception{
        return commentAskService.replyCommentAsks(userId,askId,message,replyId,pid);
    }

    /**
     * 提问评论点赞
     */
    @PostMapping("/askCommentPraise")
    public ResponseResult askCommentPraise(String commentAskId,String userId)throws Exception{
        return commentAskService.askCommentPraise(commentAskId,userId);
    }

    /**
     * 帖子关键字查询
     */
    @PostMapping("/searchPost")
    public ResponseResult searchPost(String keyWord, @RequestParam(defaultValue = "1")Integer pageNum, @RequestParam(defaultValue = "10")Integer pageSize)throws Exception {
        return communityService.SearchPost(keyWord,pageNum,pageSize);
    }

    /**
     * 社区关键字搜索前十的数据
     */
    @PostMapping("/hotKeyword")
    public ResponseResult hotKeyword()throws Exception{
        return  communityService.hotKeyword();
    }

    /**
     * 我看过的历史
     */
    @PostMapping("/findHistory")
    public ResponseResult findHistory(String userId, @RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "10") Integer pageSize){
        return  communityService.findHistory(userId,pageNum,pageSize);
    }

    /**
     * 查询研究院帖子
     */
    @PostMapping("/searchResearch")
    public ResponseResult SearchResearch(String keyWord, @RequestParam(defaultValue = "1")Integer pageNum, @RequestParam(defaultValue = "10")Integer pageSize)throws Exception {
        return communityService.SearchResearch(keyWord,pageNum,pageSize);
    }

    /**
     * 我的提问
     */
    @PostMapping("/findUserAsk")
    public ResponseResult findUserAsk(String userId, @RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "10") Integer pageSize)throws Exception{
        return communityService.findUserAsk(userId,pageNum,pageSize);
    }

    /**
     *我关注的
     */
    @PostMapping("/findCollectionAsk")
    public ResponseResult findCollectionAsk(String userId, @RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "10") Integer pageSize)throws Exception{
        return communityService.findCollectionAsk(userId,pageNum,pageSize);
    }

    /**
     * 我的消息
     */
    @PostMapping("/findNews")
    public ResponseResult findNews(String userId, @RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "10") Integer pageSize)throws Exception{
        return communityService.findNews(userId,pageNum,pageSize);
    }

    /**
     * 我的消息活动
     */
    @PostMapping("/findActivityPost")
    public ResponseResult findActivityPost(@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "10") Integer pageSize)throws Exception{
        return  communityService.findActivityPost(pageNum,pageSize);
    }

    /**
     * 删除我看过的历史
     */
    @PostMapping("/deleteHistory")
    public ResponseResult deleteHistory(String userId)throws Exception{
        return  communityService.deleteHistory(userId);
    }

    /**
     * 分享app加积分
     */
    @PostMapping("/shareIntegral")
    public ResponseResult shareIntegral(String status,String shareId, String userId,String news)throws Exception{
        return researchService.shareIntegral(status,shareId,userId,news);
    }

    /**
     * 查询社区首页轮播图
     *
     * @return
     * @throws Exception
     */
    @PostMapping("/listResearchBanner")
    public ResponseResult listResearchBanner() throws Exception {
        return commentResearchService.listResearchBanner();
    }

    /**
     * 研究社活动运营数据统计
     * @param researchId
     * @param activeType 0活动弹窗打开 1网页 2活动GIF 3商城轮播图,4社区轮播图 5活动分享 6 活动弹窗关闭
     * @return
     * @throws Exception
     */
    @PostMapping("/researchActive")
    public ResponseResult researchActive(String researchId,Integer activeType)throws Exception{
        return researchService.researchActive(researchId, activeType);
    }
}
